/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package converter;

import model.Laminaat;
import Jama.Matrix;
import java.util.TreeMap;

/**
 *
 * @author Memet
 */
public class Ansys {

    private static int Matid;
    private static int Lamid;


    //todo refactpr
    public static String ToAnsysADPL(double e1, double e2, double e3, double g12, double g23, double g31, double nu12, double nu23, double nu31, double rho, String name, double a1, double a2, double a3)
    {
        /*
        Matid = Global.data.getNextAnsysMaterialID();
        String adpl = "/COM,"+name+"\n" +
                "MPTEMP,,,,,,,,\n"+
                "MPTEMP,1,0\n"+
                "MPDATA,EX,"+Matid+",,"+e1+"\n"+ //E1
                "MPDATA,EY,"+Matid+",,"+e2+"\n"+ //E2
                "MPDATA,EZ,"+Matid+",,"+e3+"\n"+ //E3
                "MPDATA,PRXY,"+Matid+",,"+nu12+"\n"+ //Nu12
                "MPDATA,PRYZ,"+Matid+",,"+nu23+"\n"+ //Nu23
                "MPDATA,PRXZ,"+Matid+",,"+nu31+"\n"+ //Nu31
                "MPDATA,GXY,"+Matid+",,"+g12+"\n"+ //G12
                "MPDATA,GYZ,"+Matid+",,"+g23+"\n"+ //G23
                "MPDATA,GXZ,"+Matid+",,"+g31+"\n"+ //G31
                "MPDATA,CTEX,"+Matid+",,"+a1+"\n"+ //a1
                "MPDATA,CTEY,"+Matid+",,"+a2+"\n"+ //a2
                "MPDATA,CTEZ,"+Matid+",,"+a3+"\n"+ //a3
                "MPDATA,DENS,"+Matid+",,"+rho+""; //Rho

        return adpl; */ return "";
    }

    //TODO refactor
    @Deprecated
    public static String ToAnsysADPL(Laminaat lam, String secoffset)
    {
        String adpl = "";
        TreeMap<Integer, Integer> hernummeringstabel = new TreeMap<Integer, Integer>();
        /*
        for(int i = 0; i<lam.getLam().getRowDimension(); i++)
        {

            Materiaal m = Global.data.getMateriaal((int)lam.getLam().get(i, 1));
            if(!hernummeringstabel.containsKey(m.getId()))
            {
                double e1m = m.getE1();
                double e2m = m.getE2();
                double e3m = m.getE3();
                double g12m = m.getG12();
                double g23m = m.getG23();
                double g31m = m.getG31();
                double nu12m = m.getNu12();
                double nu23m = m.getNu23();
                double nu31m = m.getNu31();
                double rhom = m.getRho();
                double a1 = m.getA1();
                double a2 = m.getA2();
                double a3 = m.getA3();
                adpl += ToAnsysADPL(e1m, e2m, e3m, g12m, g23m, g31m, nu12m, nu23m, nu31m, rhom, m.getNaam(), a1, a2, a3)+"\n\n\n";
                hernummeringstabel.put(m.getId(), Global.data.getLastAnsysMaterialID());
            }
        }

        Lamid = Global.data.getNextAnsysLaminateID();
        adpl += "sect,"+Lamid+",shell,, \n";
        for(int i = 0; i<lam.getLam().getRowDimension(); i++)
        {
            double thickness = lam.getLam().get(i, 3);
            double orientation = lam.getLam().get(i, 2);
            int matid = hernummeringstabel.get((int)lam.getLam().get(i, 1));
            adpl += "secdata, "+thickness+","+matid+","+orientation+",3\n";
        }
        */
        adpl+="secoffset,"+secoffset+"\nseccontrol,,,, , , ,";
        return adpl;
    }


    //todo refactor
    /*
    public static String ToAnsysADPL(Materiaal mat)
    {
        return ToAnsysADPL(mat.getE1(), mat.getE2(), mat.getE3(), mat.getG12(), mat.getG23(), mat.getG31(), mat.getNu12(), mat.getNu23(), mat.getNu31(), mat.getRho(), mat.getNaam(), mat.getA1(), mat.getA2(), mat.getA3());
    } */

    public static String ToAnsysADPL(Matrix a, Matrix b, Matrix d, Matrix nt, Matrix mt, double rho)
    {
        double a11 = a.get(0, 0);
        double a21 = a.get(1, 0);
        double a22 = a.get(1, 1);
        double a31 = a.get(2, 0);
        double a32 = a.get(2, 1);
        double a33 = a.get(2, 2);
        double b11 = b.get(0, 0);
        double b21 = b.get(1, 0);
        double b22 = b.get(1, 1);
        double b31 = b.get(2, 0);
        double b32 = b.get(2, 1);
        double b33 = b.get(2, 2);
        double d11 = d.get(0, 0);
        double d21 = d.get(1, 0);
        double d22 = d.get(1, 1);
        double d31 = d.get(2, 0);
        double d32 = d.get(2, 1);
        double d33 = d.get(2, 2);
        double nt11 = nt.get(0, 0);
        double nt22 = nt.get(1, 0);
        double nt12 = nt.get(2, 0);
        double mt11 = nt.get(0, 0);
        double mt22 = nt.get(1, 0);
        double mt12 = nt.get(2, 0);
        /*            //todo refactor
        Lamid = Global.data.getNextAnsysLaminateID();
        String adpl = "SECT,"+Lamid+", GENS,,\n"+
            "SSPA,"+a11+","+a21+","+a31+","+a22+","+a32+","+a33+"\n"+
            "SSPB,"+b11+","+b21+","+b31+","+b22+","+b32+","+b33+"\n"+
            "SSPD,"+d11+","+d21+","+d31+","+d22+","+d32+","+d33+"\n"+
            "SSPE,,,\n"+
            "SSMT,"+nt11+","+nt22+","+nt12+"\n"+
            "SSBT,"+mt11+","+mt22+","+mt12+"\n"+
            "SSPM,"+rho;
        return adpl;*/
        return "";
    }

    public static String startCode(int coords)
    {
        return "esel,s,mat,,MATID\nemod,all,esys,"+String.valueOf(coords)+"\nesel,all\n\n\r";
    }

    public static String startCode()
    {
        return startCode(12);
    }
}
